<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<script th:inline="javascript">
  $(document).ready(function(){
      $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});
      $('#transferContainer').transfer({
          titles: ['待选银行', '已选银行'],
          search: true,
          uniqueId: 'bankCode', //唯一id
          type: 'post',
          maxSelect: 20,
          diffKey: 'flag',
          unselectColumns: [{
              field: 'flag',
              checkbox: true
          }, {
              field: 'bankName',
              title: '银行名称'
          }]
      });
      changeData();
  });
  $(function(){
	  middlegroup.admin.menu[[${OP.menuId}]].save = function(obj) {
	      //获取银行编码
          //获取选中的值
          var selectData = $('#transferContainer').transfer('getData', 'selectData');
          var selectCode = '';
          Object.keys(selectData).forEach(function (key) {
              selectCode += selectData[key].bankCode + ",";
          });
          selectCode=(selectCode.substring(selectCode.length-1)==',')?selectCode.substring(0,selectCode.length-1):selectCode;
          $('#bank_code').attr("value", selectCode);

          var unselectData = $('#transferContainer').transfer('getData', 'unselectData');
          var unselectCode = '';
          Object.keys(unselectData).forEach(function (key) {
              unselectCode += unselectData[key].bankCode + ",";
          });
          unselectCode=(unselectCode.substring(unselectCode.length-1)==',')?unselectCode.substring(0,unselectCode.length-1):unselectCode;
          $('#unselect_bank_code').attr("value", unselectCode);
          $('#service_type').attr("disabled",false);

		var $form = $("#menu[[${OP.menuId}]]Form");  		
  		if($form.valid()){
  			middlegroup.ajaxJson({url:"/op_save_[[${OP.menuId}]]",data:$form.serializeArray()},function(){
  				middlegroup.closeWindow();
				$('#admin_menu[[${OP.menuId}]]_datagrid').bootstrapTable('refresh');
    		});
  		}; 
	};	 
  });
  function changeData() {
      var code = $('#code_id').val();
      $.ajax({
          url: [[${MENU.channel}]] + '/getChannelBanks' + "?code=" + code,
          success: function (json) {
              $('#transferContainer').transfer('refresh', json);
          }
      });

  }
</script>
<div class="ibox float-e-margins animated fadeInRight">
	<div class="ibox-content">
		<form class="form-horizontal m-t required-validate" th:id="@{menu{menuId}Form(menuId=${OP.menuId})}" method="POST" >
			<input type="hidden" name="id" th:value="${dto?.id}" />
			<input type="hidden" name="bankCode" id="bank_code">
			<input type="hidden" name="unselectBankCode" id="unselect_bank_code">
			<div class="form-group">
				<label class="col-sm-3 control-label">通道名称：</label>
				<div class="col-sm-8">
					<input name="name" class="form-control" type="text"
						th:value="${dto?.name}" validate="{required:true,messages:{required:'请填写通道名称'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">通道编码：</label>
				<div class="col-sm-8">
					<input name="code" class="form-control" id="code_id" th:readonly="${null != dto?.id}" th:value="${dto?.code}"
						validate="{required:true,messages:{required:'请填写通道编码'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否输验证码：</label>
				<div class="col-sm-8">
					<div class="radio i-checks radio-inline">
						<label><input type="radio" value="1" th:checked="${dto?.needValidCode == true}" name="needValidCode" /><i></i> 是 </label>
					</div>
					<div class="radio i-checks radio-inline">
						<label><input type="radio" value="0" th:checked="${dto?.needValidCode != true}" name="needValidCode" /><i></i> 否 </label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">结算周期：</label>
				<div class="col-sm-8">
					<select class="form-control m-b" name="settleCycle">
						<option value="0">请选择结算周期</option><p ></p>
						<option th:each="settleCycle : ${settleCycles}" th:value="${settleCycle.name}" th:selected="${settleCycle.name == dto?.settleCycle} ? 'selected'" th:text="${settleCycle.text}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">结算方式：</label>
				<div class="col-sm-8">
					<select class="form-control m-b" name="settleMethod">
						<option value="0">请选择结算方式</option><p ></p>
						<option th:each="settleMethod : ${settleMethods}" th:value="${settleMethod.name}" th:selected="${settleMethod.name == dto?.settleMethod} ? 'selected'" th:text="${settleMethod.text}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">结算费率：</label>
				<div class="col-sm-8">
					<input name="settleRate" class="form-control" th:value="${dto?.settleRate}"
						   validate="{required:true,messages:{required:'请填写结算费率'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">垫资费用：</label>
				<div class="col-sm-8">
					<input name="capitalCost" class="form-control" th:value="${dto?.capitalCost}"
						   validate="{required:true,messages:{required:'请填写垫资费用'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">其它费用：</label>
				<div class="col-sm-8">
					<input name="otherCost" class="form-control" th:value="${dto?.otherCost}"
						   validate="{required:true,messages:{required:'请填写其它费用'}}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">类型：</label>
				<div class="col-sm-8">
					<select class="form-control m-b" name="serviceType" th:disabled="${null != dto?.id}" id="service_type" >
						<option value="0">请选择类型</option><p ></p>
						<option th:each="serviceType : ${serviceTypes}" th:value="${serviceType.serviceCode}" th:selected="${serviceType.serviceCode == dto?.serviceType} ? 'selected'" th:text="${serviceType.name}"></option>
					</select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="radio i-checks radio-inline">
						<label><input type="radio" value="1" th:checked="${dto?.enabled == 1}" name="enabled" /><i></i> 启动 </label>
					</div>
					<div class="radio i-checks radio-inline">
						<label><input type="radio" value="0" th:checked="${dto?.enabled != 1}" name="enabled" /><i></i> 禁用 </label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">银行绑定：</label>
				<div class="col-sm-8">
					<div id="transferContainer" class="row" style="height: 600px;width: 100%;"></div>
				</div>

			</div>
		</form>
	</div>
</div>
</html>